﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace helloworld2
{
    class RoadContainer
    {
        private static RoadContainer instance=null;
        private List<Road> roads = new List<Road>();

        private RoadContainer()
        {
        }

        public static RoadContainer Instance
        {
            get
            {
                if (instance==null)
                {
                    instance = new RoadContainer();
                }
                return instance;
            }
        }
       
        

        public List<Road> getRoads()
        {
            var roadList = new List<Road>();
            foreach(Road r in roads)
            {
                roadList.Add(r);
            }
            return roadList;
        }


        public void addRoad(Road newRoad)
        {
            roads.Add(newRoad);
            
        }

        public Road findRoad(int id)
        {
            Road r = null;
            for (int i = 0; i < roads.Count; i++)
            {
                if (roads[i].id == id)
                {
                    r = roads[i];
                }
            }
            return r;
        }

        public Road getRoadByIndex(int index)
        {
            Road r = roads[index];
            return r;
        }

        public Road getRoadByCoordinates(KeyValuePair<int, int> coordinates)
        {
            Road r = new Road();
            for (int i = 0; i < roads.Count; i++)
            {
                r = roads[i];
                if (r.lookForCoordinates(coordinates))
                {
                    i = roads.Count;
                }
            }
            return r;
        }

        public Road getRoad(int id)
        {
            Road result = roads[5];
            foreach (Road r in roads)
            {
                if (r.getId() == id)
                {
                    result = r;
                }
                
            }
            return result;
        }
    }
}
